<script>
  $('gEditor').retrieve('setTabs',function(){
    var gtabs=$ES('#menu-desktop .spage-side-nav li.l-handle');
    new ItemAgg(gtabs,$ES('#gEditor .spage-main-box'),{
      activeName:'cur',
      onActive:function(tab,item){
        var anotherItems=$$($A(this.items).remove(item));
        if(tab.hasClass('all')){
          $E('.std-upload-txt').fade('show');
          anotherItems.show();
        }else{
          $E('.std-upload-txt').fade('hide');
          anotherItems.hide();
        }
      }
    });
  }());
</script>

<h3 ><{t}>基本信息<{/t}></h3>
<div id="x-g-basic" class="goods-detail">
  <div class="tableform" >
    <table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <th><{t}>供应商：<{/t}></th>
        <td>
          <{input type="object" breakpoint=1 object="business_basicmsg" value="{$goods.business.business_id}" textcol="english_all_name" name="goods[business][business_id]" callback='bussiness_change'}>
        </td>
      </tr>

      <tr>
        <th><{t}>分类：<{/t}></th>
        <td>
          <{input type="category" value="{$goods.category.cat_id}" name="goods[category][cat_id]"}>
        </td>
      </tr>
      <!--tag_foreign_extcat-->
      <{if $extends_goods_edit_html}>
      <{$extends_goods_edit_html}>
      <{/if}>
      <tr>
        <th><{t}>类型：<{/t}></th>
        <td><select name="goods[type][type_id]" id="gEditor-GType-input">
          <!--<option value='1'><{t}>通用商品类型<{/t}></option>-->
          <{foreach from=$gtype item=type}>
          <option class="optionlevels" value='<{$type.type_id}>' <{if $type.type_id==$goods.type.type_id}>selected<{/if}>><{$type.name}>
          </option>
          <{/foreach}>
        </select>
        </td>
      </tr>
      <tr>
        <th><{t}>商品名称：<{/t}></th>
        <td><{input type="text" id="id_gname" name="goods[name]" required="true" vtype='required' value=$goods.name style="width:60%"}><em><font color="red">*</font></em></td>
      </tr>
      <{if $goodsbn_display_switch}>
      <tr>
        <th><{t}>商品编号：<{/t}></th>
        <td><{input type="text" name="goods[bn]" value=$goods.bn }></td>
      </tr>
      <{else}>
      <input type='hidden' name="goods[bn]" value="<{$goods.bn}>">
      <{/if}>

      <tr>
        <th><{t}>商品关键词：<{/t}></th>
        <td><{foreach from=$goods.keywords item=keywords}><{assign var='keyword' value="{$keyword}|{$keywords.keyword}"}><{/foreach}><input type="text" name="keywords" value="<{$keyword|trim:'|'}>" class="inputstyle" maxlength="100"/><span class="notice-inline "><{t}>仅用于在前台、后台筛选商品，多个关键词用半角竖线"|"分开<{/t}></span></td>
      </tr>
      <tr>
        <th><{t}>品牌：<{/t}></th>
        <td id="select_brand"><{input class='select-brand' type="select" name="goods[brand][brand_id]" nulloption="1" rows=$brandList valueColumn="brand_id" labelColumn="brand_name" value=$goods.brand.brand_id}></td>
      </tr>
      <tr>
        <th><{t}>结算方式：<{/t}></th>
        <td><span id='account_mode'><{$goods.brand.account_mode}></span><span class="notice-inline "></span></td>
      </tr>
      <th><{t}>返点率：<{/t}></th>
      <td><span id='brand_rebate'><{$goods.brand.rebate}></span><span>%</span></td>
      </tr>
      <tr>
      <tr>
        <th><{t}>商品简介：<{/t}></th>
        <td><{input type="textarea" class="x-input" value=$goods.brief name="goods[brief]" style="resize:none;" cols="50" rows="5" maxth="255" }>
          <div class="notice-inline"><{t}>简短的商品介绍,请不要超过70个字<{/t}></div></td>
      </tr>

      <tr>
        <th><{t}>模板：<{/t}></th>
        <td>
          <{template_filter type="product" class="inputstyle" selected=$goods.goods_setting.goods_template name="goods[goods_setting][goods_template]"}></td>
      </tr>

      <tr>
        <th>
          <{t}>商品相册：<{/t}>
        </th>

        <td>
          <div class="division pic-main" style="margin:0;position:relative">
            <div class="clearfix">
              <span class="pic-uploader">
                <{button app="desktop" class="btn-upload" label=$___b2c="添加商品图片"|t:'b2c' icon="image_new.gif"}>
              </span>
            </div>

            <div class="pic-area">
              <input type="hidden" name="image_default" value="<{$goods.image_default_id}>" />
              <{include file="admin/goods/detail/img/gimage_goods.html"}>
            </div>

          </div>
        </td>
      </tr>
      <th>
        <{t}>列表页图片：<{/t}>
      </th>
      <td>
        <input id="udfimg-false" type="radio" name="goods[udfimg]" value=false <{if $goods.udfimg != 'true'}>checked<{/if}> />
        <label for="udfimg-false" ><{t}>用商品相册默认图<{/t}></label>
        <input id="udfimg-true" type="radio" name="goods[udfimg]" value=true <{if $goods.udfimg == 'true'}>checked<{/if}> />
        <label for="udfimg-true" ><{t}>自定义商品列表页图片<{/t}></label>


        <div id="imageuparea" style="display:<{if $goods.udfimg=='true'}>block<{else}>none<{/if}>">
          <h4 style="margin:0"><{t}>商品在列表页显示的图片<{/t}></h4>
          <{input name="goods[thumbnail_pic]" type="image" value=$goods.thumbnail_pic width="120" height="90"}>
        </div>

        <script>
          $$('#x-g-basic input[name^=goods[udfimg]').addEvent('click',function(){

            if($('udfimg-true').checked){
              $('imageuparea').show();
            }else{
              $('imageuparea').hide();
            }

          });
        </script>
      </td>

      <{if $env.conf.b2c.goods.package_use.switch}>
      <tr>
        <th><{t}>开启打包：<{/t}></th>
        <td>
          <input type="radio"  name="goods[package_use]"<{if $goods.package_use eq 1 }> checked="checked"<{/if}> value="1" ><{t}>是<{/t}>
          <input type="radio"  name="goods[package_use]"<{if $goods.package_use eq 0}> checked="checked"<{/if}> value="0" ><{t}>否<{/t}>
        </td>
      </tr>
      <tr class="package_use" <{if $goods.package_use eq 0 }>style="display:none"<{/if}>>
      <th><{t}>打包数量：<{/t}></th>
      <td><{input type="unsigned" value=$goods.package_scale name="goods[package_scale]" style="width:60px" maxlength="25" }><{t}>（多少个一包）<{/t}></td>
      </tr>
      <tr class="package_use" <{if $goods.package_use eq 0 }>style="display:none"<{/if}>>
      <th><{t}>打包单位：<{/t}></th>
      <td><{input type="text" value=$goods.package_unit name="goods[package_unit]" style="width:60px" maxlength="25" }>（即每包的英文单位，如lot, box, carton等）<{t}><{/t}></td>
      </tr>
      <{/if}>
    </table>
  </div>

  <div class="tableform" id="goods-spec">
    <{if $goods.spec }>
    <{if count($goods.product)>100 }>
    <input type="hidden" name="spec_load">
    <div class="loading"></div>
    <script>
      new Request.HTML({url:'index.php?app=b2c&ctl=admin_goods_editor&act=getSpecHtml&p[0]=<{$goods.goods_id}>',onRequest:function(){
        $E('#goods-spec .loading').innerHTML='正在加载规格.......';
      },update:'goods-spec'}).send();
    </script>
    <{else}>
    <{include file="admin/goods/detail/spec/spec.html"}>
    <{/if}>

    <{else}>
    <{include file="admin/goods/detail/spec/nospec.html"}>
    <{/if}>

  </div>
  <{if $goods.type.setting.use_props}>
  <div class="tableform">
    <{t}><h4>扩展属性</h4><{/t}>
    <table border="0" cellpadding="0" cellspacing="0">
      <{if $goods.type.setting.use_props}>
      <{foreach from=$goods.type.props key=key item=aProp}>
      <tr class="prop">
        <th><{$aProp.name}>：</th>
        <td>
          <{assign var="p_col" value="p_{$key}"}>
          <{if $aProp.type eq 'select'}>
          <input type="hidden" name="goods[props][p_<{$key}>][type]" value="select">
          <{if $aProp.is_multi eq 'false'}>
          <{foreach from=$aProp.options key=optkey item=opt}>
          <input type="radio" name="goods[props][p_<{$key}>][value][]" value="<{$optkey}>" <{if in_array($optkey,$extend)}>checked<{/if}>><{$opt}>
          <{/foreach}>
          <{elseif $aProp.is_multi eq 'true'}>
          <{foreach from=$aProp.options key=optkey item=opt}>
          <input type="checkbox"   name="goods[props][p_<{$key}>][value][]" <{if in_array($optkey,$extend)}>checked<{/if}> value="<{$optkey}>" ><{$opt}>
          <{/foreach}>
          <{/if}>
          <{else}>
          <input type="hidden" name="goods[props][p_<{$key}>][type]" value="input">
          <{input type="text"  name="goods[props][p_{$key}][value]" placeholder=$__b2c="可以不输入"|t:'b2c' maxlength="25" style="width:55px" value="{$extend[$p_col].value}"}>
          <{/if}></td>
      </tr>
      <{/foreach}>
      <{/if}>
    </table>
  </div>
  <{/if}>



  <div class="tableform">
    <table border="0" cellpadding="0" cellspacing="0">
      <!--tag_foreign_freeshipping-->
      <tr>
        <th><{t}>自定义上架时间：<{/t}></th>
        <td>
          <!--<{input type="input" name="goods[myuptime]" value=$goods.myuptime}>-->
          <input type="text" name="goods[myuptime]" value="<{$goods.myuptime|cdate:FDATE_FTIME}>" disabled >
        </td>
      </tr>
      <{if $site_min_order == 'true'}>
      <tr>
        <th><{t}>起定量：<{/t}></th>
        <td><{input type="unsigned" value=$goods.min_buy name="goods[min_buy]" style="width:25px" maxlength="25" }><span class='min-buy-unit'>&nbsp;<{$goods.unit}><span></td>
      </tr>
      <{/if}>



      <tr>
        <th><{t}>立即上架：<{/t}></th>
        <td>
          <{permission perm_id='editmarketable'}>
          <input type="radio" name="goods[status]"<{if $goods.status != 'false' }> checked="checked"<{/if}> value="true" ><{t}>是<{/t}>
          <input type="radio" name="goods[status]"<{if $goods.status == "false"}> checked="checked"<{/if}> value="false" ><{t}>否<{/t}>
          <{/permission}>
        </td>
      </tr>
      <tr>
        <th><{t}>库存提示规则：<{/t}></th>
        <td>
          <{permission perm_id='editgoods'}>
          <{input type="select" name="goods[store_prompt]" options=$store_prompt value=$goods.store_prompt}>
          <{/permission}>
        </td>
      </tr>

      <tr>
        <th><{t}>库存确认：<{/t}></th>
        <td><input type="radio" name="goods[sto_confirm]" value='Y' <{if $goods.sto_confirm=='Y'}>checked<{/if}>><{t}>需要<{/t}>&nbsp;&nbsp;&nbsp;
          <input type="radio" name="goods[sto_confirm]" value='N' <{if $goods.sto_confirm=='N'}>checked<{/if}>><{t}>不需要<{/t}></td>
      </tr>

      <tr>
        <th><{t}>无库存也可销售：<{/t}></th>
        <td>
          <{permission perm_id='nostore_sell'}>
          <input type="radio"  name="goods[nostore_sell]"<{if $goods.nostore_sell eq 1 }> checked="checked"<{/if}> value="1" ><{t}>是<{/t}>
          <input type="radio"  name="goods[nostore_sell]"<{if $goods.nostore_sell eq 0}> checked="checked"<{/if}> value="0" ><{t}>否<{/t}>
          <{/permission}>
        </td>
      </tr>

      <tr>
        <th><{t}>是否预售商品：<{/t}></th>
        <td>
          <input type="radio" name="goods[pre_sale]"<{if $goods.pre_sale == 'true'}>checked="checked"<{/if}> value="true" ><{t}>是<{/t}>
          <input type="radio" name="goods[pre_sale]"<{if $goods.pre_sale != "true"}> checked="checked"<{/if}> value="false" ><{t}>否<{/t}>
        </td>
      </tr>

      <{if $env.conf.b2c.site.get_policy.method ==3}>
      <tr>
        <th><{t}>积分：<{/t}></th>
        <td><{input type="digits" value=$goods.gain_score name="goods[gain_score]" maxlength="25" }><input type='hidden' name='goods[score_setting]' value='number'/></td>
      </tr>
      <{/if}>
    </table>
  </div>




</div>
<script>
  //mll 添加、编辑商品时，预售信息的显示和隐藏
//  jQuery(function(){
//    var pre_radio  = jQuery('input[name="goods[pre_sale]"]:checked');
//    function pre_info_show(){
//      pre_radio.parent().parent().next().show();
//      pre_radio.parent().parent().next().next().show();
//    }
//    function pre_info_hide(){
//      pre_radio.parent().parent().next().hide();
//      pre_radio.parent().parent().next().next().hide();
//    }
//    if(pre_radio.val()==='true'){
//      pre_info_show();
//    }else{
//      pre_info_hide();
//    }
//    jQuery('input:radio[name="goods[pre_sale]"][value="false"]').click(function(){
//      pre_info_hide();
//    })
//    jQuery('input:radio[name="goods[pre_sale]"][value="true"]').click(function(){
//      pre_info_show();
//    })
//  })
  //end
  //--------liuyulei--------
  jq(function(){
    writePrice();
  });
  function writePrice(){
    if(jq('#account_mode').text()=='自由定价'){
      jq('.cost-price').removeAttr('readonly');
    }
    jq('.s-price').bind('change',function(){
      var num = jq('.unit-num').val();
      var l_price = jq(this).val();
      jq('.sale-price').val(parseFloat(l_price*num));
    });
  }
  //---------liuyulei end------
  (function(){
    $ES('#x-g-basic input[name^=goods[package_use]').addEvent('click',function(e){

      var v=this.checked&&this.value=="1"?[false,'']:[true,'none'];

      $$('.package_use').each(function(el){
        el.setStyle('display',v[1]).getElement('input').set('disabled',v[0]);
      });
    });


  })();
  function price_control(){
    var rebate=1-$('brand_rebate').get('html')/100;
    if($('account_mode').get('html')=='返点' ){
      //销售单价 by yyj 2015/10/19
      if($$('.s-price')){
        $$('.unit-num').removeEvents('change').addEvent('change',function(e){
          var s_price = $$('.s-price').get('value');
          $$('.sale-price').set('value',(this.value*s_price).toFixed(2));
          $$('.cost-price').set('value',(s_price*rebate).toFixed(2));
          //var cost = $$('.sale-price').get('value');
          //$$('.cost-price').set('value',(cost*rebate).toFixed(2));
        });
        $$('.s-price').addEvent('change',function(e){
          var unit_num = $$('.unit-num').get('value');
          $$('.sale-price').set('value',(this.value*unit_num).toFixed(2));
          $$('.cost-price').set('value',(this.value*rebate).toFixed(2));
          //var cost = $$('.sale-price').get('value');
          //$$('.cost-price').set('value',(cost*rebate).toFixed(2));
        });
        $$('.unit-num').set('readonly','');
        $$('.s-price').set('readonly','');

      }

      $$('.sale-price').addEvent('change',
              function(){
                //var cost=this.value;
                //$$('.cost-price').set('value',(cost*rebate).toFixed(2));
                var unit_num = $$('.unit-num').get('value');
                $$('.s-price').set('value',(this.value/unit_num).toFixed(2));
                var s_price = $$('.s-price').get('value');
                $$('.cost-price').set('value',(s_price*rebate).toFixed(2));

              }
      );
      //$$('.sale-price').set('readonly','');
      $$('.cost-price').set('readonly','true');
      $$('.ladder-price').set('readonly','');
      $$('.ladder-cost-price').set('readonly','true');
      $$('.ladder-price').addEvent('change',
              function(){
                var cost=this.value;

                $$('.ladder-cost-price').set('value',(cost*rebate).toFixed(2));
              }
      );
      $$('.account-tips').setStyle('display','none');
      $$('.rebate-tips').setStyle('display','block');
    }
    //-------------liuyulei 自由定价--------------
    if($('account_mode').get('html')=='自由定价'){
      jq('.cost-price').removeAttr('readonly');
      $$('.cost-price').addEvent('change',
              function(){
                var cost=this.value;
                //$$('.s-price').set('value',(cost/rebate).toFixed(2));
                var num = $$('.unit-num').get('value');
                var l_price = $$('.s-price').get('value');
                //$$('.sale-price').set('value',(l_price*num).toFixed(2));
              }
      );
      $$('.cost-price').set('readonly','');

      //销售单价 by yyj 2015/10/19
//                  if($$('.s-price')){
//                    $$('.s-price').set('readonly','true');
//                  }

      $$('.ladder-cost-price').set('readonly','');
      $$('.ladder-price').set('readonly','true');
      $$('.ladder-cost-price').addEvent('change',
              function(){
                var cost=this.value;
                $$('.ladder-price').set('value',(cost/rebate).toFixed(2));
              }
      );
      $$('.unit-num').removeEvents('change').addEvent('change',function(e){
        var s_price = $$('.s-price').get('value');
        var num = $$('.unit-num').get('value');
        $$('.sale-price').set('value',(s_price*num).toFixed(2));
      });
      $$('.rebate-tips').setStyle('display','none');
      $$('.account-tips').setStyle('display','block');
    }
    //-------------liuyulei 自由定价 end--------------
    if($('account_mode').get('html')=='结算价'){
      $$('.cost-price').addEvent('change',
              function(){
                var cost=this.value;
                /*
                 $$('.sale-price').set('value',(cost/rebate).toFixed(2));
                 var l_price = $$('.sale-price').get('value');
                 var num = $$('.unit-num').get('value');
                 $$('.s-price').set('value',(l_price/num).toFixed(2));*/
                $$('.s-price').set('value',(cost/rebate).toFixed(2));
                var num = $$('.unit-num').get('value');
                //var l_price = $$('.sale-price').get('value');
                var l_price = $$('.s-price').get('value');
                $$('.sale-price').set('value',(l_price*num).toFixed(2));
              }
      );
      $$('.cost-price').set('readonly','');
      //$$('.sale-price').set('readonly','true');

      //销售单价 by yyj 2015/10/19
      if($$('.s-price')){
        $$('.s-price').set('readonly','true');
      }

      $$('.ladder-cost-price').set('readonly','');
      $$('.ladder-price').set('readonly','true');
      $$('.ladder-cost-price').addEvent('change',
              function(){
                var cost=this.value;
                $$('.ladder-price').set('value',(cost/rebate).toFixed(2));
              }
      );
      $$('.unit-num').removeEvents('change').addEvent('change',function(e){
        var s_price = $$('.s-price').get('value');
        var num = $$('.unit-num').get('value');
        $$('.sale-price').set('value',(s_price*num).toFixed(2));
      });
      $$('.rebate-tips').setStyle('display','none');
      $$('.account-tips').setStyle('display','block');
    }
  }
  price_control();
  function brand_change(){
    $$('.select-brand').addEvent('change',function(){
      var brand=this.value;
      new Request.JSON({
        url:'index.php?app=b2c&ctl=admin_goods_editor&act=update_brand',
        method:'post',
        data:'brand_id='+brand,
        onSuccess:function(re){
          $('brand_rebate').set('html',re.rebate);
          $('account_mode').set('html',re.account_mode);
          price_control();
          if(re.account_mode=='返点'  || re.account_mode=='自由定价'){
            $$('.account-tips').setStyle('display','none');
            $$('.rebate-tips').setStyle('display','block');
          }else{
            $$('.account-tips').setStyle('display','block');
            $$('.rebate-tips').setStyle('display','none');
          }
        }
      }).send();
    });
  }
  brand_change();
  /*tag_foreign_js_extcat*/
  /*供应商联动品牌*/
  function bussiness_change(obj){
    var business_id=JSON.parse(obj).id;
    var type_id=$('gEditor-GType-input').value;
    new Request.JSON({
      url:'index.php?app=b2c&ctl=admin_goods_editor&act=update',
      method:'post',
      data:'business_id='+business_id+'&type_id='+type_id,
      onSuccess:function(r){
        var tpl='<select class="select-brand x-select" nulloption="1" name="goods[brand][brand_id]" type="select"><option></option>';
        var i=0;
        for(i;i<r.data.length;i++){
          tpl+='<option value="'+r.data[i].brand_id+'">'+r.data[i].brand_name+'</option>';
        }
        tpl+='</select>';
        $('select_brand').innerHTML=tpl;
        /*var i=0;
         for(i;i<r.data.length;i++){
         $('select_brand')[i].innerHTML='<option value="'+r.data[i].brand_id+'">'+r.data[i].brand_name+'</option>';
         }*/
        $('account_mode').set('html','');
        $('brand_rebate').set('html','');
        brand_change();
      }
    }).send();
  }
  //阶梯价格开启与关闭
  function open_ladder(){
    $$('.ladder-open').addClass('hide');
    $$('.ladder-close').removeClass('hide');
    $$('.ladder').removeClass('hide');
    var input=$$('.ladder').getElements('input');
    input.each(function(e,v){
      e.set('value','');
    });
    $$('.is-open').set('value','true');
  }
  function close_ladder(){
    $$('.ladder-close').addClass('hide');
    $$('.ladder-open').removeClass('hide');
    $$('.ladder').addClass('hide');
    var input=$$('.ladder').getElements('input');
    input.each(function(e,v){
      e.set('value','');
    });
    $$('.is-open').set('value','false');
  }

  function unit_change(obj){
    var tpl='1&nbsp;'+obj.value+'&nbsp;=';
    $$('.bag-unit').set('html',tpl);
    $$('.min-buy-unit').set('html','&nbsp;'+obj.value);
  }
  $$('.ladder-num').addEvent('change',function(){
    if(this.value=='0'||this.value=='1'){
      this.value='2';
      return MessageBox.error('阶梯数量不能小于2');
    }
  });
</script>




